package com.koron.css2.baseConfig.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.DateUtils;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
 * 公共属性
 */
public class BaseBean {
	/**
	 * 主键ID
	 */
	private String id;
	
	/**
	 * 预留字段
	 */
	private String tenantId;
	
	/**
	 * 建立时间
	 */
	private String createTime;
	
	/**
	 * 建立人
	 */
	private String createName;
	
	/**
	 * 建立人ID
	 */
	private String createAccount;
	
	/**
	 * 最后修改时间
	 */
	private String updateTime;
	
	/**
	 * 最后修改人
	 */
	private String updateName;
	
	/**
	 * 最后修改人ID
	 */
	private String updateAccount;

	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date startQueryTime;		// 查询时间中的开始时间
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date endQueryTime;		// 查询时间中的结束时间
	private List<String> timeQueryRange;		// 查询时间中的时间范围

	public Date getStartQueryTime() {
		return startQueryTime;
	}

	public void setStartQueryTime(Date startQueryTime) {
		this.startQueryTime = startQueryTime;
	}

	public Date getEndQueryTime() {
		return endQueryTime;
	}

	public void setEndQueryTime(Date endQueryTime) {
		this.endQueryTime = endQueryTime;
	}

	public void setTimeQueryRange(List<String> timeQueryRange) {
		if (timeQueryRange == null || timeQueryRange.size() != 2 || StringUtils.isBlank(timeQueryRange.get(0)) || StringUtils.isBlank(timeQueryRange.get(1))) {
			this.timeQueryRange = null;
		} else {
			try {
				this.setStartQueryTime(DateUtils.parseDate(timeQueryRange.get(0), "yyyy-MM-dd"));
				this.setEndQueryTime(DateUtils.parseDate(timeQueryRange.get(1), "yyyy-MM-dd"));
				this.timeQueryRange = timeQueryRange;
			} catch (ParseException e) {
				this.timeQueryRange = null;
			}
		}
	}

	public List<String> getTimeQueryRange() {
		if (startQueryTime != null && endQueryTime != null) {
			timeQueryRange = new ArrayList<>();
			timeQueryRange.add(0, DateUtils.parseDate(startQueryTime, "yyyy-MM-dd"));
			timeQueryRange.add(1, DateUtils.parseDate(endQueryTime, "yyyy-MM-dd"));
		}
		return timeQueryRange;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTenantId() {
		return tenantId;
	}

	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getCreateName() {
		return createName;
	}

	public void setCreateName(String createName) {
		this.createName = createName;
	}

	public String getCreateAccount() {
		return createAccount;
	}

	public void setCreateAccount(String createAccount) {
		this.createAccount = createAccount;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateName() {
		return updateName;
	}

	public void setUpdateName(String updateName) {
		this.updateName = updateName;
	}

	public String getUpdateAccount() {
		return updateAccount;
	}

	public void setUpdateAccount(String updateAccount) {
		this.updateAccount = updateAccount;
	}

	public void setCreateInfo(UserInfoBean userInfo) {
		setId(Tools.getObjectId());
		setCreateAccount(userInfo.getUserInfo().getAcount());
		setCreateName(userInfo.getUserInfo().getName());
		setTenantId(userInfo.getCurWaterCode());
		setCreateTime(DateUtils.parseDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
	}
	
	public void setUpdateInfo(UserInfoBean userInfo) {
		setUpdateAccount(userInfo.getUserInfo().getAcount());
		setUpdateName(userInfo.getUserInfo().getName());
		setUpdateTime(DateUtils.parseDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
	}
	
	
}
